import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/mynote/index")
public class NoteIndexServlet extends HttpServlet {
    //重写init()方法
    @Override
    public void init() throws ServletException {
        super.init();
        System.out.println("欢迎访问note页面！");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String method = req.getMethod();
        PrintWriter out = resp.getWriter();
        String name=req.getParameter("name");
        out.println("<html>");
        out.println("<head><title>我的笔记首页</title></head>");
        out.println("<body>");
        out.println("<center><h1>" + "欢迎访问note页面！" + "</h1></center>");
        out.println("<center><h1>使用的方法是： " + method + " </h1></center>");
        out.println("<center><h1>欢迎 " + name+ " 访问张毅的首页</h1></center>");
        out.println("<center><h1>" + "我是张毅 学号：2321241086" + "</h1></center>");
        out.println("</body>");
        out.println("</html>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}

